<?php
  if($step != 2)
    die();
    
  require_once('./includes/funcs_wow.php');
    
  $sql_return = @mysql_query('SELECT * FROM `'.TAB_SRC.'` WHERE `id`='.intval(addslashes($_POST['background'])).' AND `type`="SIGNATURE" LIMIT 1');
  $sql_data = @mysql_fetch_assoc($sql_return);
?>


<!-- STYLES -->
<style type="text/css">
  .form table {
    margin: auto;
  }
  
  .head2 {
    font-size: 22px;
    color: purple;
  }
  
  .tab_submit {
    text-align: right;
  }
</style>

<!-- SCRIPTS -->
<script type="text/javascript">
<!--
  function refreshPrev(param) {
    document.getElementById('preview').src = './includes/get_preview.php?get=<?php echo $sql_data['id']; ?>&get2='+param;
  }
  
  function setVisibility(how) {
    for(i=1; i<=<?php echo($sql_data['fields']); ?>; i++) {
      document.getElementById('record_'+i).style.display = 'none';
    }
    
    for(i=1; i<=how; i++) {
      document.getElementById('record_'+i).style.display = 'table-row';
    }
  }
  
  function checkOption(id, value) {
    if(value == 0)
      document.getElementById('TextField_'+id).disabled = '';
    else
      document.getElementById('TextField_'+id).disabled = 'disabled';
  }
-->
</script>

<!-- BODY -->  
    <table>
      <tr>
        <td class="head2" style="padding-bottom: 8px;" colspan="2">
          Set number of texts and values: 
        </td>
      </tr>
      <tr>
        <td colspan="2">
          How many texts?:
          <select name="num_texts" onchange="setVisibility(this.value); refreshPrev(this.value);">
            <option value="<?php echo $sql_data['fields']; ?>">All</option>
            <?php
              for($i=1; $i<=$sql_data['fields']; $i++) {
                echo '<option value="'.$i.'">'.$i.'</option>';
              }
            ?>
          </select>
          <input type="hidden" name="sign_type" value="<?php echo $_POST['sign_type']; ?>">
          <input type="hidden" name="background" value="<?php echo $_POST['background']; ?>">
        </td>
      </tr>

<?php
  if($_POST['sign_type'] == 0) {
    for($i=1; $i<=$sql_data['fields']; $i++) {
      if($i == 1) $text = 'Only Character Name'; else $text = 'Text '.$i;
      echo ('
        <tr id="record_'.$i.'">
          <td>
            '.$text.': 
          </td>
          <td>
            <input type="text" name="value_'.$i.'">
          </td>
        </tr>
      ');
    }
  } else {
    $str='';
    $opts = get_values(PATCH);
    
    for($x=1; $x<=count($opts); $x++) {
      $str .= '<option value="'.$x.'">'.$opts[$x].'</option> ';
    }
    
    for($i=1; $i<=$sql_data['fields']; $i++) {
      if($i == 1) {
        echo ('
          <tr id="record_'.$i.'">
            <td>
              Only Character Name: 
            </td>
            <td>
              <input type="text" name="value_'.$i.'" maxlength="50">
            </td>
          </tr>
        ');
      } else {
        echo ('
          <tr id="record_'.$i.'">
            <td>
              Text '.$i.': 
            </td>
            <td>
              <select name="func_'.$i.'" onchange="checkOption('.$i.', this.value);">
                <option value="0">My text</option>
                '.$str.'
              </select>
              
              <input type="text" id="TextField_'.$i.'" name="value_'.$i.'" maxlength="50">
            </td>
          </tr>
        ');
      }
    }
  }
?>

      <tr>
        <td colspan="2">
          <img id="preview" src="./includes/get_preview.php?get=<?php echo $sql_data['id']; ?>&get2=9" title="<?php echo $sql_data['name']; ?>" alt="<?php echo $sql_data['name']; ?>" />
        </td>
      </tr>
      
      <tr>
        <td class="tab_submit" colspan="2">
          <input type="submit" name="step2" value="Continue &#187;">
        </td>
      </tr>
    </table>